package com.ruoyi.project.xcx.myhome.category.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.xcx.myhome.category.domain.XcxMyhomeCategory;
import com.ruoyi.project.xcx.myhome.category.service.IXcxMyhomeCategoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * myhome分类Controller
 * 
 * @author ruoyi
 * @date 2020-03-10
 */
@Controller
@RequestMapping("/myhome/category")
public class XcxMyhomeCategoryController extends BaseController
{
    private String prefix = "myhome/category";

    @Autowired
    private IXcxMyhomeCategoryService xcxMyhomeCategoryService;

    @RequiresPermissions("myhome:category:view")
    @GetMapping()
    public String category()
    {
        return prefix + "/category";
    }

    /**
     * 查询myhome分类列表
     */
    @RequiresPermissions("myhome:category:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XcxMyhomeCategory xcxMyhomeCategory)
    {
        startPage();
        List<XcxMyhomeCategory> list = xcxMyhomeCategoryService.selectXcxMyhomeCategoryList(xcxMyhomeCategory);
        return getDataTable(list);
    }

    /**
     * 导出myhome分类列表
     */
    @RequiresPermissions("myhome:category:export")
    @Log(title = "myhome分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XcxMyhomeCategory xcxMyhomeCategory)
    {
        List<XcxMyhomeCategory> list = xcxMyhomeCategoryService.selectXcxMyhomeCategoryList(xcxMyhomeCategory);
        ExcelUtil<XcxMyhomeCategory> util = new ExcelUtil<XcxMyhomeCategory>(XcxMyhomeCategory.class);
        return util.exportExcel(list, "category");
    }

    /**
     * 新增myhome分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存myhome分类
     */
    @RequiresPermissions("myhome:category:add")
    @Log(title = "myhome分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XcxMyhomeCategory xcxMyhomeCategory)
    {
        return toAjax(xcxMyhomeCategoryService.insertXcxMyhomeCategory(xcxMyhomeCategory));
    }

    /**
     * 修改myhome分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        XcxMyhomeCategory xcxMyhomeCategory = xcxMyhomeCategoryService.selectXcxMyhomeCategoryById(id);
        mmap.put("xcxMyhomeCategory", xcxMyhomeCategory);
        return prefix + "/edit";
    }

    /**
     * 修改保存myhome分类
     */
    @RequiresPermissions("myhome:category:edit")
    @Log(title = "myhome分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XcxMyhomeCategory xcxMyhomeCategory)
    {
        return toAjax(xcxMyhomeCategoryService.updateXcxMyhomeCategory(xcxMyhomeCategory));
    }

    /**
     * 删除myhome分类
     */
    @RequiresPermissions("myhome:category:remove")
    @Log(title = "myhome分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xcxMyhomeCategoryService.deleteXcxMyhomeCategoryByIds(ids));
    }
}
